<?php
header("Cache-Control: no-cache, must-revalidate");
    $name=$_GET["name"];
    $con = mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("tubetogether", $con);
    $sql="SELECT * FROM pushmessages WHERE Receiver = '$name'";

    $result = mysql_query($sql);
    $arr=array();

    while ($row=mysql_fetch_array($result)) {
        $arr[]=array("PID" => $row['PID'], "Sender" => $row['Sender'], "Filename" => $row['Filename']);
    }

    if (count($arr)>0) {
        $sql="DELETE FROM pushmessages WHERE PID IN (";
        foreach($arr as $k => $v) {
            $sql=$sql.$arr[$k]['PID'].",";
        }
        $sql=substr($sql, 0, strlen($sql)-1).")";
    }

    $result = mysql_query($sql);
    mysql_close($con);
    echo "<?xml version=\"1.0\"?>\n";
    echo "<messages>\n";
    foreach($arr as $k => $v) {
        echo "<item>\n";
        echo "<sender>".$arr[$k]['Sender']."</sender>\n";
        echo "<message>".$arr[$k]['Filename']."</message>\n";
        echo "</item>\n";
    }
    echo "</messages>\n";
    
?>
